﻿// 3. Write a program to convert decimal numbers to their hexadecimal representation.

using System;

class DecimalToHexidecimalNumbers
{
    static void Main()
    {
        Console.Write("Enter your decimal number : ");
        string decimalNumberStr = Console.ReadLine();
        int decimalNumber = int.Parse(decimalNumberStr);

        string hexNumber = "";
        hexNumber = ConvertIntoHexadecimal(decimalNumber);

        Console.WriteLine("The hexadecimal representation of the decimal number {0} is {1}.", decimalNumberStr, hexNumber);
    }

    static string ConvertIntoHexadecimal(int decimalNumber)
    {
        string hexNumber = "";
        int remainder = 0;
        char remainderChar;

        while (decimalNumber > 0)
        {
            remainder = decimalNumber % 16;
            decimalNumber /= 16;

            switch (remainder)
            {
                case 0: remainderChar = '0'; break;
                case 1: remainderChar = '1'; break;
                case 2: remainderChar = '2'; break;
                case 3: remainderChar = '3'; break;
                case 4: remainderChar = '4'; break;
                case 5: remainderChar = '5'; break;
                case 6: remainderChar = '6'; break;
                case 7: remainderChar = '7'; break;
                case 8: remainderChar = '8'; break;
                case 9: remainderChar = '9'; break;
                case 10: remainderChar = 'A'; break;
                case 11: remainderChar = 'B'; break;
                case 12: remainderChar = 'C'; break;
                case 13: remainderChar = 'D'; break;
                case 14: remainderChar = 'E'; break;
                case 15: remainderChar = 'F'; break;
                default: remainderChar = ' '; break;
            }

            hexNumber = remainderChar + hexNumber;
        }

        return hexNumber;
    }
}
